<?php

declare(strict_types=1);

namespace WanZ\App\User\Action;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\Context\Context;
use MoChat\Framework\Action\AbstractAction;
use WanZ\App\Utils\Prometheus\PrometheusFactory;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;

/**
 * 获取用户服务度量指标值集
 * @Controller
 */
class ServMetrics extends AbstractAction
{        
    /**
     * @RequestMapping(path="/common/get-metrics", methods="GET")
     * @return array 返回数组
     */
    public function handle(): array
    {       
        $data = PrometheusFactory::all()->getAllMetrics();
        return Context::get(ResponseInterface::class)->withBody(new SwooleStream($data))->withStatus(200);
    }
}